//
//  OrderInfoViewController.m
//  HTP
//
//  Created by 王鑫 on 15/11/2.
//  Copyright © 2015年 nit. All rights reserved.
//

#import "OrderInfoViewController.h"

@interface OrderInfoViewController ()

@property (nonatomic, retain) UIImageView *topTextImage;

@property (nonatomic, retain) UIImageView *topIcoImage;

@property (nonatomic, retain) UIView *topVIew;

@property (nonatomic, retain) UILabel *orderIDLabel;

@property (nonatomic, retain) UILabel *teacherNameLabel;

@property (nonatomic, retain) UILabel *priceLabel;

@property (nonatomic, retain) UILabel *teachNumberLabel;

@property (nonatomic, retain) UILabel *NewTimeLabel;

@property (nonatomic, retain) UILabel *moneyLabel;

@property (nonatomic, retain) UILabel *payTimeLabel;

@property (nonatomic, retain) UIButton *alipayButton;

@property (nonatomic, retain) UIButton *balanceButton;

@property (nonatomic, retain) UIButton *payButton;

@end

@implementation OrderInfoViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self initUI];
    // Do any additional setup after loading the view.
}


//TODO:UI绘制 -- wangxin
- (void)initUI{
    _topVIew = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 130)];
    _topVIew.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"fukuanbg"]];
    [self.view addSubview:self.topVIew];
    
    _topTextImage = [[UIImageView alloc] initWithFrame:CGRectMake(55, 50, 110, 40)];
    if ([_flag isEqualToString:@"true"]) {
        _topTextImage.image = [UIImage imageNamed:@"yifukuan"];
    }else
        _topTextImage.image = [UIImage imageNamed:@"wifukuan"];
    [_topVIew addSubview:self.topTextImage];
    
    _topIcoImage = [[UIImageView alloc] initWithFrame:CGRectMake(ScreenWidth - 110, 10, 70, 110)];
    if ([_flag isEqualToString:@"true"]) {
        [_topIcoImage setFrame:CGRectMake(ScreenWidth - 130, 10, 110, 110)];
        _topIcoImage.image = [UIImage imageNamed:@"gantanhao"];
    }else
        _topIcoImage.image = [UIImage imageNamed:@"wenhao"];
    [_topVIew addSubview:self.topIcoImage];
    
    UIImageView *line = [[UIImageView alloc] initWithFrame:CGRectMake(0, 130, ScreenWidth, 1)];
    line.image = [UIImage imageNamed:@"line"];
    [line setAlpha:0.6];
    [self.view addSubview:line];
    
    _orderIDLabel = [[UILabel alloc] initWithFrame:CGRectMake(30, 150, 240, 25)];
    _orderIDLabel.font = [UIFont systemFontOfSize:16.0f];
    _orderIDLabel.text = @"订单编号:100000000000";
    [self.view addSubview:self.orderIDLabel];
    
    _teacherNameLabel = [[UILabel alloc] initWithFrame:CGRectMake(30, 180, 240, 25)];
    _teacherNameLabel.font = [UIFont systemFontOfSize:16.0f];
    _teacherNameLabel.text = @"教师:孙庆涛";
    [self.view addSubview:self.teacherNameLabel];
    
    _priceLabel = [[UILabel alloc] initWithFrame:CGRectMake(30, 210, 240, 25)];
    _priceLabel.font = [UIFont systemFontOfSize:16.0f];
    _priceLabel.text = @"单价:200元/次";
    [self.view addSubview:self.priceLabel];
    
    _teachNumberLabel = [[UILabel alloc] initWithFrame:CGRectMake(30, 240, 240, 25)];
    _teachNumberLabel.font = [UIFont systemFontOfSize:16.0f];
    _teachNumberLabel.text = @"上课次数:10次";
    [self.view addSubview:self.teachNumberLabel];
    
    _NewTimeLabel = [[UILabel alloc] initWithFrame:CGRectMake(30, 270, 240, 25)];
    _NewTimeLabel.font = [UIFont systemFontOfSize:16.0f];
    _NewTimeLabel.text = @"创建时间:2015-03-05 21:22:22";
    [self.view addSubview:self.NewTimeLabel];
    
    _moneyLabel = [[UILabel alloc] initWithFrame:CGRectMake(ScreenWidth - 100, 340, 80, 20)];
    [_moneyLabel setFont:[UIFont systemFontOfSize:19.0f]];
    _moneyLabel.textColor = [UIColor orangeColor];
    _moneyLabel.text = @"1500.00";
    [self.view addSubview:self.moneyLabel];
    
    _payTimeLabel = [[UILabel alloc] initWithFrame:CGRectMake(30, 300, 240, 25)];
    _payTimeLabel.font = [UIFont systemFontOfSize:16.0f];
    _payTimeLabel.text = @"付款时间:2015-08-08 22:22:22";
    
    if ([_flag isEqualToString:@"false"]) {
        
        [_moneyLabel setFrame:CGRectMake(ScreenWidth - 100, 405, 80, 20)];
         
        _alipayButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 310, ScreenWidth, 40)];
        _alipayButton.selected = true;
        [self setButtonIcoImage:@"订单详情_15" ofText:@"支付宝付款" button:_alipayButton];
        [self.view addSubview:self.alipayButton];
        
        _balanceButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 350, ScreenWidth, 40)];
        [self setButtonIcoImage:@"yuer" ofText:@"余额支付" button:_balanceButton];
        [self.view addSubview:self.balanceButton];
        
        _payButton = [[UIButton alloc] initWithFrame:CGRectMake((ScreenWidth - 280) / 2.0, 440, 280, 35)];
        _payButton.backgroundColor = [UIColor colorWithRed:83 / 255.0 green:216 / 255.0 blue:22 / 255.0 alpha:1];
        _payButton.layer.cornerRadius = 7.0;
        _payButton.titleLabel.font = [UIFont systemFontOfSize:20.0f];
        [_payButton setTitle:@"去付款" forState:UIControlStateNormal];
        [self.view addSubview:self.payButton];
        
    }else
        [self.view addSubview:self.payTimeLabel];
 
}

//TODO:支付类型按钮样式设置 -- wangxin
- (void)setButtonIcoImage:(NSString *)image ofText:(NSString *)text button:(UIButton *)button {
    
    [button.layer setBorderWidth:1];
    [button.layer setBorderColor:[UIColor colorWithRed:0.8 green:0.8 blue:0.8 alpha:0.6].CGColor];
    [button setBackgroundImage:[UIImage imageNamed:@"zhuangtaibg"] forState:UIControlStateSelected];
    
    if ([image isEqualToString:@"yuer"]) {
        [button addTarget:self action:@selector(balanceButtonDown) forControlEvents:UIControlEventTouchUpInside];
    }else
        [button addTarget:self action:@selector(alipayButtonDown) forControlEvents:UIControlEventTouchUpInside];

    UIImageView *icoImage = [[UIImageView alloc] initWithFrame:CGRectMake(35, 5, 30, 30)];
    icoImage.image = [UIImage imageNamed:image];
    [button addSubview:icoImage];
    
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(100, 10, 90, 20)];
    label.text = text;
    [button addSubview:label];
}

//TODO:支付按钮2选1的实现 --wangxin
- (void)alipayButtonDown {
    _alipayButton.selected = true;
    _balanceButton.selected = false;
}

- (void)balanceButtonDown {
    _alipayButton.selected = false;
    _balanceButton.selected = true;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
